<template>
  <div  class="p16 flex-column-null-between container">
    <el-row>
      <el-col :span="6">
        <div class="grid-content bg-purple">
          <div slot="header" class="top-from">系统列表
            <el-button style="margin-left: 50px" type="success" size="mini" icon="el-icon-refresh"  @click="refreshSystem">刷新</el-button>
          </div>
          <div style="margin-top:2px;overflow: auto;height: calc(100vh - 240px)">
            <el-tree
                :data="systemData"
                :props="defaultProps"
                highlight-current
                :expand-on-click-node="cacheExpandOnClickNode"
                @node-click="handleNodeClick">
            </el-tree>
          </div>
        </div>
      </el-col>

      <el-col :span="9">
        <div class="grid-content bg-purple-light">
          <div slot="header" class="top-from">缓存定义： {{nowSystem.systemName}}
          </div>
          <div style="overflow: auto;height: calc(100vh - 240px)">

            <el-table
                :data="cacheData"
                size="small"
                @current-change="handleCacheChange"
                :row-style="{height:'0'}"
                style="width: 100%"
                :highlight-current-row="cacheHighLight"
                v-loading="cacheLoading">
              <el-table-column
                  prop="key"
                  label="缓存前缀"
                  min-width="250">
              </el-table-column>
              <el-table-column
                  prop="desc"
                  label="缓存定义名称"
                  min-width="150">
              </el-table-column>
            </el-table>

          </div>
        </div>
      </el-col>

      <el-col :span="9">
        <div class="grid-content bg-purple">
          <div slot="header" class="top-from">缓存Key
          </div>

          <div style="overflow: auto;height: calc(100vh - 240px)">
            <el-table
                :data="cacheKeyTable"
                size="small"
                :row-style="{height:'0'}"
                style="width: 100%"
                v-loading="cacheKeyLoading">
              <el-table-column
                  prop="key"
                  label="缓存key"
                  min-width="250">
              </el-table-column>

              <el-table-column
                  prop="operate"
                  min-width="100"
                  label="操作">
                <template  scope="scope">
                  <el-button @click="getCacheValue(scope.row)" type="text" size="mini">查看详情</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>


          <el-dialog
              :visible.sync="dialogVisible"
              :before-close="closeDialog"
              append-to-body
              title="请求参数"
          >
            <el-input :autosize="{ minRows: 5, maxRows: 20}" show-word-limit type="textarea"   placeholder="请输入内容"  v-model="nowCacheValue"></el-input>
          </el-dialog>
        </div>

      </el-col>
    </el-row>
  </div>
</template>

<script>
import{queryCacheSystemList,getRedisValue,queryRedisKeys} from '@/api/control';
export default {
  components:{
  },
  data() {
    return {
      dialogVisible:false,
      cacheHighLight:true,
      systemExpandOnClickNode:false,
      cacheExpandOnClickNode:false,
      cacheLoading:false,
      cacheKeyLoading:false,
      topNumber:0,
      leftNumber:0,
      optionCardShow:false,
      //系统树
      systemData:[],
      defaultProps:{
        children: 'child',
        label: 'systemName'
      },
      cacheData:[],
      cacheDataProps:{
        children: 'child',
        label: 'desc'
      },
      cacheKeyTable:[],
      //当前选中系统
      nowSystem:{},
      //当前选中缓存定义
      nowCache:{},
      //当前选中缓存key
      nowCacheKey:{},
      nowCacheValue:"",
    }

  },
  created(){
    this.querySystemCacheData();
  },
  methods:{
    //刷新
    refreshSystem(){
      this.querySystemCacheData();
    },
    async querySystemCacheData(){
      let res = await queryCacheSystemList();
      this.systemData = res.data;
    },
    handleNodeClick(system){
      if(system == null){
        return;
      }
      this.nowSystem = system;
      this.cacheData = system.cacheKey;
    },
    handleCacheChange(row){
      if(row == null){
        return;
      }
      this.nowCache = row;
      this.queryCacheKeys();
    },
    //查询岗位下员工
    async queryCacheKeys(){
      if(this.nowCache == null){
        return;
      }
      let res = await queryRedisKeys({prefixKey:this.nowCache.key});
      this.cacheKeyTable = res.data;
    },
    closeDialog(){
      this.dialogVisible = false;
      this.nowCacheValue = "";
    },
    async getCacheValue(row){
      this.dialogVisible = true;
      let res = await getRedisValue({key:row.key});
      this.nowCacheValue = JSON.stringify(JSON.parse(res.data),null,2);
    }
  }

}
</script>


<style src="../../css/index.scss" lang="scss"></style>
<style lang="scss" scoped>

.folder-box {
  height: 100%;
}

.option-card-button {
  width: 100%;
  margin-left: 0;
  font-size: 12px;
  border-radius: 0;
}
.search-item{
  float: left;
  margin: 0 20px 20px 0;
  span{
    color: #606266;
    font-size: 14px;
    margin-right: 10px;
  }
}

.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  /* background: #d3dce6; */
}
.bg-purple-light {
  /* background: #e5e9f2; */
}
.top-from{
  height: 50px;
}
.grid-content {
  border: 1px solid #e1e4e7;
  border-radius: 4px;
  margin-top: 0px;
  background: #fff;
  //设置内容高度随浏览器变化
  height: calc(100vh - 160px);
  //min-height:  600px;
  overflow: auto;
  padding-top: 15px;
  padding-left: 20px;
  padding-right: 20px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

</style>
